import { Model, DataTypes, Optional } from 'sequelize';
import sequelize from '@/config/database';

export interface NoticeAttributes {
  noticeId?: number;
  noticeTitle: string;
  noticeType: string;
  noticeContent?: string;
  status?: string;
  createBy?: string;
  createTime?: Date;
  updateBy?: string;
  updateTime?: Date;
  remark?: string;
}

export interface NoticeCreationAttributes extends Optional<NoticeAttributes, 'noticeId'> {}

class Notice extends Model<NoticeAttributes, NoticeCreationAttributes> implements NoticeAttributes {
  public noticeId!: number;
  public noticeTitle!: string;
  public noticeType!: string;
  public noticeContent?: string;
  public status?: string;
  public createBy?: string;
  public createTime?: Date;
  public updateBy?: string;
  public updateTime?: Date;
  public remark?: string;

  public readonly createdAt!: Date;
  public readonly updatedAt!: Date;
}

Notice.init(
  {
    noticeId: {
      type: DataTypes.INTEGER,
      primaryKey: true,
      autoIncrement: true,
      field: 'notice_id',
    },
    noticeTitle: {
      type: DataTypes.STRING(50),
      allowNull: false,
      field: 'notice_title',
    },
    noticeType: {
      type: DataTypes.CHAR(1),
      allowNull: false,
      field: 'notice_type',
    },
    noticeContent: {
      type: DataTypes.TEXT,
      field: 'notice_content',
    },
    status: {
      type: DataTypes.CHAR(1),
      defaultValue: '0',
      field: 'status',
    },
    createBy: {
      type: DataTypes.STRING(64),
      defaultValue: '',
      field: 'create_by',
    },
    createTime: {
      type: DataTypes.DATE,
      field: 'create_time',
    },
    updateBy: {
      type: DataTypes.STRING(64),
      defaultValue: '',
      field: 'update_by',
    },
    updateTime: {
      type: DataTypes.DATE,
      field: 'update_time',
    },
    remark: {
      type: DataTypes.STRING(255),
      field: 'remark',
    },
  },
  {
    sequelize,
    tableName: 'sys_notice',
    timestamps: true,
    createdAt: 'createTime',
    updatedAt: 'updateTime',
  }
);

export default Notice; 